From 006dfdc55a6de5e111c4867414a39f377d12852e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 14 Jun 2020 07:07:30 +0200 Subject: [PATCH] selectionmodel: Remove select_callback() functions gtk_selection_model_set_selection() takes care of those now. --- docs/reference/gtk/gtk4-sections.txt | 3 -- gtk/gtkmultiselection.c | 75 ---------------------------- gtk/gtkpropertyselection.c | 69 ------------------------- gtk/gtkselectionmodel.c | 59 ---------------------- gtk/gtkselectionmodel.h | 47 ----------------- 5 files changed, 253 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 85f2ef371a..739415f6cd 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -398,9 +398,6 @@ gtk_selection_model_unselect_range gtk_selection_model_select_all gtk_selection_model_unselect_all gtk_selection_model_set_selection -GtkSelectionCallback -gtk_selection_model_select_callback -gtk_selection_model_unselect_callback gtk_selection_model_selection_changed diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c index 048be34cd4..367d5e6384 100644 --- a/gtk/gtkmultiselection.c +++ b/gtk/gtkmultiselection.c @@ -144,86 +144,11 @@ gtk_multi_selection_set_selection (GtkSelectionModel *model, return TRUE; } -static gboolean -gtk_multi_selection_add_or_remove (GtkSelectionModel *model, - gboolean unselect_rest, - gboolean add, - GtkSelectionCallback callback, - gpointer data) -{ - GtkMultiSelection *self = GTK_MULTI_SELECTION (model); - guint pos, start, n_items; - gboolean in; - guint min, max; - guint n; - - n = g_list_model_get_n_items (G_LIST_MODEL (self)); - - min = G_MAXUINT; - max = 0; - - if (unselect_rest) - { - min = gtk_bitset_get_minimum (self->selected); - max = gtk_bitset_get_maximum (self->selected); - gtk_bitset_remove_all (self->selected); - } - - for (pos = 0; pos < n; pos = start + n_items) - { - callback (pos, &start, &n_items, &in, data); - - if (n_items == 0) - break; - - g_assert (start <= pos && pos < start + n_items); - - if (in) - { - if (start < min) - min = start; - if (start + n_items - 1 > max) - max = start + n_items - 1; - - if (add) - gtk_bitset_add_range (self->selected, start, n_items); - else - gtk_bitset_remove_range (self->selected, start, n_items); - } - - pos = start + n_items; - } - - if (min <= max) - gtk_selection_model_selection_changed (model, min, max - min + 1); - - return TRUE; -} - -static gboolean -gtk_multi_selection_select_callback (GtkSelectionModel *model, - gboolean unselect_rest, - GtkSelectionCallback callback, - gpointer data) -{ - return gtk_multi_selection_add_or_remove (model, unselect_rest, TRUE, callback, data); -} - -static gboolean -gtk_multi_selection_unselect_callback (GtkSelectionModel *model, - GtkSelectionCallback callback, - gpointer data) -{ - return gtk_multi_selection_add_or_remove (model, FALSE, FALSE, callback, data); -} - static void gtk_multi_selection_selection_model_init (GtkSelectionModelInterface *iface) { iface->is_selected = gtk_multi_selection_is_selected; iface->set_selection = gtk_multi_selection_set_selection; - iface->select_callback = gtk_multi_selection_select_callback; - iface->unselect_callback = gtk_multi_selection_unselect_callback; } G_DEFINE_TYPE_EXTENDED (GtkMultiSelection, gtk_multi_selection, G_TYPE_OBJECT, 0, diff --git a/gtk/gtkpropertyselection.c b/gtk/gtkpropertyselection.c index 0430d0ed04..f3f973f075 100644 --- a/gtk/gtkpropertyselection.c +++ b/gtk/gtkpropertyselection.c @@ -167,80 +167,11 @@ gtk_property_selection_set_selection (GtkSelectionModel *model, return TRUE; } -static gboolean -gtk_property_selection_add_or_remove (GtkSelectionModel *model, - gboolean unselect_rest, - gboolean add, - GtkSelectionCallback callback, - gpointer data) -{ - GtkPropertySelection *self = GTK_PROPERTY_SELECTION (model); - guint pos, start, n, n_items; - gboolean in; - guint min, max; - guint i; - - n_items = g_list_model_get_n_items (G_LIST_MODEL (self)); - if (unselect_rest) - { - for (i = 0; i < n_items; i++) - set_selected (self, i, FALSE); - } - - min = G_MAXUINT; - max = 0; - - pos = 0; - do - { - callback (pos, &start, &n, &in, data); - if (in) - { - if (start < min) - min = start; - if (start + n - 1 > max) - max = start + n - 1; - - for (i = start; i < start + n; i++) - set_selected (self, i, add); - } - pos = start + n; - } - while (n > 0); - - /* FIXME: do better here */ - if (unselect_rest) - gtk_selection_model_selection_changed (model, 0, n_items); - else if (min <= max) - gtk_selection_model_selection_changed (model, min, max - min + 1); - - return TRUE; -} - -static gboolean -gtk_property_selection_select_callback (GtkSelectionModel *model, - gboolean unselect_rest, - GtkSelectionCallback callback, - gpointer data) -{ - return gtk_property_selection_add_or_remove (model, unselect_rest, TRUE, callback, data); -} - -static gboolean -gtk_property_selection_unselect_callback (GtkSelectionModel *model, - GtkSelectionCallback callback, - gpointer data) -{ - return gtk_property_selection_add_or_remove (model, FALSE, FALSE, callback, data); -} - static void gtk_property_selection_selection_model_init (GtkSelectionModelInterface *iface) { iface->is_selected = gtk_property_selection_is_selected; iface->set_selection = gtk_property_selection_set_selection; - iface->select_callback = gtk_property_selection_select_callback; - iface->unselect_callback = gtk_property_selection_unselect_callback; } G_DEFINE_TYPE_EXTENDED (GtkPropertySelection, gtk_property_selection, G_TYPE_OBJECT, 0, diff --git a/gtk/gtkselectionmodel.c b/gtk/gtkselectionmodel.c index c62efbb538..0a60d7310d 100644 --- a/gtk/gtkselectionmodel.c +++ b/gtk/gtkselectionmodel.c @@ -209,23 +209,6 @@ gtk_selection_model_default_unselect_range (GtkSelectionModel *model, return result; } -static gboolean -gtk_selection_model_default_select_callback (GtkSelectionModel *model, - gboolean unselect_rest, - GtkSelectionCallback callback, - gpointer data) -{ - return FALSE; -} - -static gboolean -gtk_selection_model_default_unselect_callback (GtkSelectionModel *model, - GtkSelectionCallback callback, - gpointer data) -{ - return FALSE; -} - static gboolean gtk_selection_model_default_select_all (GtkSelectionModel *model) { @@ -258,8 +241,6 @@ gtk_selection_model_default_init (GtkSelectionModelInterface *iface) iface->select_all = gtk_selection_model_default_select_all; iface->unselect_all = gtk_selection_model_default_unselect_all; iface->set_selection = gtk_selection_model_default_set_selection; - iface->select_callback = gtk_selection_model_default_select_callback; - iface->unselect_callback = gtk_selection_model_default_unselect_callback; /** * GtkSelectionModel::selection-changed @@ -556,46 +537,6 @@ gtk_selection_model_set_selection (GtkSelectionModel *model, return iface->set_selection (model, selected, mask); } -/** - * gtk_selection_model_select_callback: - * @model: a #GtkSelectionModel - * @unselect_rest: whether previously selected items should be unselected - * @callback: (scope call): a #GtkSelectionCallback to determine items to select - * @data: data to pass to @callback - * - * Requests to select all items for which @callback returns - * @selected as TRUE. - */ -gboolean -gtk_selection_model_select_callback (GtkSelectionModel *model, - gboolean unselect_rest, - GtkSelectionCallback callback, - gpointer data) -{ - g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), FALSE); - - return GTK_SELECTION_MODEL_GET_IFACE (model)->select_callback (model, unselect_rest, callback, data); -} - -/** - * gtk_selection_model_unselect_callback: - * @model: a #GtkSelectionModel - * @callback: (scope call): a #GtkSelectionCallback to determine items to select - * @data: data to pass to @callback - * - * Requests to unselect all items for which @callback returns - * @selected as TRUE. - */ -gboolean -gtk_selection_model_unselect_callback (GtkSelectionModel *model, - GtkSelectionCallback callback, - gpointer data) -{ - g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), FALSE); - - return GTK_SELECTION_MODEL_GET_IFACE (model)->unselect_callback (model, callback, data); -} - /** * gtk_selection_model_selection_changed: * @model: a #GtkSelectionModel diff --git a/gtk/gtkselectionmodel.h b/gtk/gtkselectionmodel.h index 8b90fc6793..4e5722c7e6 100644 --- a/gtk/gtkselectionmodel.h +++ b/gtk/gtkselectionmodel.h @@ -33,36 +33,6 @@ G_BEGIN_DECLS GDK_AVAILABLE_IN_ALL G_DECLARE_INTERFACE (GtkSelectionModel, gtk_selection_model, GTK, SELECTION_MODEL, GListModel) -/** - * GtkSelectionCallback: - * @position: the position to query - * @start_range: (out): returns the position of the first element of the range - * @n_items: (out): returns the size of the range - * @selected: (out): returns whether items in @range are selected - * @data: callback data - * - * Callback type for determining items to operate on with - * gtk_selection_model_select_callback() or - * gtk_selection_model_unselect_callback(). - * - * The callback determines a range of consecutive items around - * @position which should either all - * be changed, in which case @selected is set to %TRUE, or all not - * be changed, in which case @selected is set to %FALSE. - * - * @start_range and @n_items are set to return the range. - * - * The callback will be called repeatedly to find all ranges - * to operate on until it has exhausted the items of the model, - * or until it returns an empty range (ie @n_items == 0). - */ -typedef void (* GtkSelectionCallback) (guint position, - guint *start_range, - guint *n_items, - gboolean *selected, - gpointer data); - - /** * GtkSelectionModelInterface: * @is_selected: Return if the item at the given position is selected. @@ -128,13 +98,6 @@ struct _GtkSelectionModelInterface gboolean (* set_selection) (GtkSelectionModel *model, GtkBitset *selected, GtkBitset *mask); - gboolean (* select_callback) (GtkSelectionModel *model, - gboolean unselect_rest, - GtkSelectionCallback callback, - gpointer data); - gboolean (* unselect_callback) (GtkSelectionModel *model, - GtkSelectionCallback callback, - gpointer data); }; GDK_AVAILABLE_IN_ALL @@ -173,16 +136,6 @@ gboolean gtk_selection_model_set_selection (GtkSelectionMod GtkBitset *selected, GtkBitset *mask); -GDK_AVAILABLE_IN_ALL -gboolean gtk_selection_model_select_callback (GtkSelectionModel *model, - gboolean unselect_rest, - GtkSelectionCallback callback, - gpointer data); -GDK_AVAILABLE_IN_ALL -gboolean gtk_selection_model_unselect_callback (GtkSelectionModel *model, - GtkSelectionCallback callback, - gpointer data); - /* for implementations only */ GDK_AVAILABLE_IN_ALL void gtk_selection_model_selection_changed (GtkSelectionModel *model, -- 2.30.2